home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / kh_gdi.zip / GD_DMAPP.CPP < prev    next >
C/C++ Source or Header  |  1996-05-11  |  6KB  |  211 lines

  1. /*  Project gdi_demo
  2.     
  3.     Copyright ⌐ 1995. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    gdi_demo.exe Application
  6.     FILE:         gd_dmapp.cpp
  7.     AUTHOR:       S.Vartanov
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of gdi_demoApp (TApplication).      
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19.  
  20. #include "gd_dmapp.h"
  21. #include "gd_dmwnd.h"                        // Definition of client class.       
  22. #include "gd_dmabd.h"                        // Definition of about dialog.       
  23.  
  24.  
  25. //{{gdi_demoApp Implementation}}
  26.  
  27.  
  28. //
  29. // Build a response table for all messages/commands handled
  30. // by the application.
  31. //
  32. DEFINE_RESPONSE_TABLE1(gdi_demoApp, TApplication)
  33. //{{gdi_demoAppRSP_TBL_BEGIN}}
  34.     EV_COMMAND(CM_FILENEW, CmFileNew),
  35.     EV_COMMAND(CM_FILEOPEN, CmFileOpen),
  36.     EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  37. //{{gdi_demoAppRSP_TBL_END}}
  38. END_RESPONSE_TABLE;
  39.  
  40.  
  41. //////////////////////////////////////////////////////////
  42. // gdi_demoApp
  43. // =====
  44. //
  45. gdi_demoApp::gdi_demoApp () : TApplication("gdi_demo")
  46. {
  47.  
  48.     // Common file file flags and filters for Open/Save As dialogs.  Filename and directory are
  49.     // computed in the member functions CmFileOpen, and CmFileSaveAs.
  50.     FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  51.     FileData.SetFilter("All Files (*.*)|*.*|");
  52.  
  53.     // INSERT>> Your constructor code here.
  54. }
  55.  
  56.  
  57. gdi_demoApp::~gdi_demoApp ()
  58. {
  59.     // INSERT>> Your destructor code here.
  60. }
  61.  
  62.  
  63. void gdi_demoApp::SetupSpeedBar (TDecoratedFrame *frame)
  64.     //
  65.     // Create default toolbar New and associate toolbar buttons with commands.
  66.     //   
  67.     TControlBar* cb = new TControlBar(frame);
  68.     cb->Insert(*new TButtonGadget(CM_FILENEW, CM_FILENEW));
  69.     cb->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN));
  70.     cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE));
  71.     cb->Insert(*new TSeparatorGadget(6));
  72.     cb->Insert(*new TButtonGadget(CM_EDITCUT, CM_EDITCUT));
  73.     cb->Insert(*new TButtonGadget(CM_EDITCOPY, CM_EDITCOPY));
  74.     cb->Insert(*new TButtonGadget(CM_EDITPASTE, CM_EDITPASTE));
  75.     cb->Insert(*new TSeparatorGadget(6));
  76.     cb->Insert(*new TButtonGadget(CM_EDITUNDO, CM_EDITUNDO));
  77.     cb->Insert(*new TSeparatorGadget(6));
  78.     cb->Insert(*new TButtonGadget(CM_EDITFIND, CM_EDITFIND));
  79.     cb->Insert(*new TButtonGadget(CM_EDITFINDNEXT, CM_EDITFINDNEXT));
  80.  
  81.     // Add fly-over help hints.
  82.     cb->SetHintMode(TGadgetWindow::EnterHints);
  83.  
  84.     frame->Insert(*cb, TDecoratedFrame::Top);
  85. }
  86.  
  87.  
  88. //////////////////////////////////////////////////////////
  89. // gdi_demoApp
  90. // =====
  91. // Application intialization.
  92. //
  93. void gdi_demoApp::InitMainWindow ()
  94. {
  95.     if (nCmdShow != SW_HIDE)
  96.         nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWMAXIMIZED : nCmdShow;
  97.  
  98.     SDIDecFrame *frame = new SDIDecFrame(0, GetName(), 0, true);
  99.  
  100.     // Override the default window style for the main window.
  101.     frame->Attr.Style |= WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE;
  102.     frame->Attr.Style &= ~(WS_CHILD | WS_THICKFRAME);
  103.  
  104.     //
  105.     // Assign ICON w/ this application.
  106.     //
  107.     frame->SetIcon(this, IDI_SDIAPPLICATION);
  108.  
  109.     //
  110.     // Menu associated with window and accelerator table associated with table.
  111.     //
  112.     frame->AssignMenu(SDI_MENU);
  113.     
  114.     //
  115.     // Associate with the accelerator table.
  116.     //
  117.     frame->Attr.AccelTable = SDI_MENU;
  118.  
  119.     SetupSpeedBar(frame);
  120.  
  121.     TStatusBar *sb = new TStatusBar(frame, TGadget::Recessed,
  122.                                     TStatusBar::CapsLock        |
  123.                                     TStatusBar::NumLock         |
  124.                                     TStatusBar::ScrollLock      |
  125.                                     TStatusBar::Overtype);
  126.     frame->Insert(*sb, TDecoratedFrame::Bottom);
  127.   
  128.     SetMainWindow(frame);
  129.  
  130.     frame->SetMenuDescr(TMenuDescr(SDI_MENU));
  131. }
  132.  
  133.  
  134. //////////////////////////////////////////////////////////
  135. // gdi_demoApp
  136. // ===========
  137. // Menu File New command
  138. void gdi_demoApp::CmFileNew ()
  139. {
  140. }
  141.  
  142.  
  143. //////////////////////////////////////////////////////////
  144. // gdi_demoApp
  145. // ===========
  146. // Menu File Open command
  147. void gdi_demoApp::CmFileOpen ()
  148. {
  149.     //
  150.     // Display standard Open dialog box to select a file name.
  151.     //
  152.     *FileData.FileName = 0;
  153.  
  154.     gdi_demoWindow *client = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), gdi_demoWindow);     // Client window for the frame.
  155.     if (client->CanClose())
  156.         if (TFileOpenDialog(GetMainWindow(), FileData).Execute() == IDOK)
  157.             OpenFile();
  158. }
  159.  
  160.  
  161. void gdi_demoApp::OpenFile (const char *fileName)
  162. {
  163.     if (fileName)
  164.         strcpy(FileData.FileName, fileName);
  165.  
  166. }
  167.  
  168.  
  169. //{{SDIDecFrame Implementation}}
  170.  
  171.  
  172. SDIDecFrame::SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, bool trackMenuSelection, TModule *module)
  173.     : TDecoratedFrame(parent, title, clientWnd == 0 ? new gdi_demoWindow(0, "") : clientWnd, trackMenuSelection, module)
  174. {
  175.     // INSERT>> Your constructor code here.
  176.  
  177. }
  178.  
  179.  
  180. SDIDecFrame::~SDIDecFrame ()
  181. {
  182.     // INSERT>> Your destructor code here.
  183.  
  184. }
  185.  
  186.  
  187. //////////////////////////////////////////////////////////
  188. // gdi_demoApp
  189. // ===========
  190. // Menu Help About gdi_demo.exe command
  191. void gdi_demoApp::CmHelpAbout ()
  192. {
  193.     //
  194.     // Show the modal dialog.
  195.     //
  196.     gdi_demoAboutDlg(MainWindow).Execute();
  197. }
  198. int OwlMain (int , char* [])
  199. {
  200.     try {
  201.         gdi_demoApp    app;
  202.         return app.Run();
  203.     }
  204.     catch (xmsg& x) {
  205.         ::MessageBox(0, x.why().c_str(), "Exception", MB_OK);
  206.     }
  207.  
  208.     return -1;
  209. }
  210.